package 集合框架.kgc.课后作业.M1;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Tsdw extends Student {
    Scanner input = new Scanner(System.in);

    private static List<Student> list = new ArrayList<>();

    static {
        list.add(new Student(1, 15, "3456566342343","张三"));
        list.add(new Student(2, 22, "3423423423444","李四"));
        list.add(new Student(3, 18, "3454354345545","沥青"));
    }


    public void show() {
        do {
            System.out.println("*********************欢迎使用学生管理系统*********************");
            System.out.println("初始化成功......");
            System.out.println("请选择您的操作\n1,显示全部学员\n2,删除\n3,增加\n4,修改\n5,退出");
            int a = input.nextInt();
            switch (a) {
                case 1:
                    //显示
                   TsDd();
                   break;
                case 2:
                    //删除
                    LoSd();
                   break;
                   //增加
                case 3:
                    PsDw();
                    break;
                    //修改
                case 4:
                    PsDws();
                    break;
                    //退出
                case 5:
                    System.out.println("感谢使用！程序成功退出...");
                    return ;


            }

        } while (true);
    }

    /**
     * 显示全部学员
     */
    public void TsDd(){
        for (int i = 0; i <list.size() ; i++) {
            System.out.println("学号:"+list.get(i).getA()+"\t年龄:"+list.get(i).getB()+
                    "\t姓名:"+list.get(i).getName()+"\t身份证号:"+list.get(i).getC());
        }
    }
    /**
     * 删除学员信息
     */
    public void LoSd(){
        for (int i = 0; i <list.size() ; i++) {
            System.out.println("请输入需要删除的学员姓名:");
            String name = input.next();
            if (list.get(i).getName().equals(name)){
                list.remove(i);
                System.out.println("删除成功！");
                break;
            }else {
                System.out.println("没有找到你要删除的姓名!");
            }
        }
    }

    /**
     * 增加学员信息
     */
    public void PsDw() {
        try {
            for (int i = 0; i <list.size() ; i++) {
                System.out.println("请输入要增加的学员学号:");
                int a = input.nextInt();
                System.out.println("请输入要增加的学员年龄:");
                int b = input.nextInt();
                System.out.println("请输入要增加学员的身份证号码:");
                String c = input.next();
                System.out.println("请输入要增加学员的姓名:");
                String m = input.next();
                if (list.get(i).getA()==a){
                    System.out.println("抱歉，该学号id已经存在！");
                    break;
                }
                list.add(new Student(a,b,c,m));
                System.out.println("添加成功!");
                break;
        }
        }catch (Exception e){
            System.out.println("发生未知错误！");
        }



    }

    /**
     * 修改学员信息
     */
    public void PsDws(){

        System.out.println("请输入学生的学号:");
        int sid = input.nextInt();

        for (int i = 0; i <list.size(); i++) {
            if (list.get(i).getA()==sid){
                System.out.println("请输入学生新的学号:");
                int a = input.nextInt();
                System.out.println("请输入学生新的姓名:");
                String name = input.next();
                System.out.println("请输入学生新的年龄:");
                int b = input.nextInt();
                System.out.println("请输入学生的新身份证号码:");
                String c = input.next();

                list.set(sid,new Student(a,b,name,c));
                System.out.println("修改成功！");
            }else {
                System.out.println("抱歉没有找到你需要修改的学员id,或输入错误！");
            }
        }



        }
    }








